<template>
  <div>
    <p class="color-666" style="margin:10px 0" :class="{ 'red-font': item.is_skip == 1 }">
      风控信息：
      <template>
        <el-select
          v-model="item.risk_suggestion"
          clearable
          placeholder="请选择"
          @change="selectLetterClick"
          @click.native="partTypesClick(item)"
        >
          <el-option
            v-for="items in options"
            :key="items.id"
            :label="items.label"
            :value="items.id"
          />
        </el-select>
      </template>
      <span style="margin-right: 10px" />
      <el-button
        size="mini"
        class="border-btn"
        @click="getRemark(item)"
      >
        备注
      </el-button>
    </p>
    <el-dialog title="备注信息" :visible.sync="dialogFormVisible">
      <el-form :model="formNotes">
        <el-form-item label="信息备注" label-width="200px">
          <p v-model="riskId" type="text" />
          <!--                  <p v-model="riskId = item.id"></p>-->
          <el-input
            v-model="inputText"
            type="textarea"
            :rows="5"
            style="width: 300px"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="riskUpdate">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { riskUpdate, riskFknote, orderClose } from './api'
export default {
  props: ['item'],
  data() {
    return {
      formNotes: {

      },
      valuesSuggest: '',
      options: [{
        id: 1,
        label: '[优]风控通过，建议发货（该类用户建议发货率80%以上)'
      }, {
        id: 2,
        label: '[良]建议适当预收客户租金，正常电审（建议发货率30%以上)'
      }, {
        id: 3,
        label: '[一般]中高风险，建议电审，如 1.通过核实用户的工作情况和累计贷款金额等，判断偿还能力；2.核实常驻地址；3.增加紧急联系人（该类用户发货率不做要求)'
      }, {
        id: 4,
        label: '[差]风控不通过，建议关闭订单'
      }, {
        id: 5,
        label: '无需输出风控'
      }
      ],
      inputText: '',
      dialogFormVisible: false,
      riskId: ''
    }
  },
  methods: {
    partTypesClick(item) {
      this.riskId = item.id
      // console.log(item.id);
    },
    getRemark(item) {
      this.inputText = ''
      this.dialogFormVisible = true
      this.riskId = item.id
      this.inputText = item.risk_note
    },
    // 风控备注信息
    riskUpdate(item) {
      // let orderId = item.id;
      const row = {}
      row.riskSuggest = this.valuesSuggest
      row.riskNote = this.inputText
      row.id = this.riskId

      if (row.riskSuggest != null || row.riskNote != null) {
        riskUpdate(row).then(res => {
          this.dialogFormVisible = false
          this.$message.success('备注成功')
        })
      } else {
        this.$message({
          message: '备注信息不能全部为空',
          type: 'error'
        })
        return false
      }
    },
    selectLetterClick(value) {
      this.valuesSuggest = value
      const data = {}
      if (this.valuesSuggest !== 4) {
        data.value = this.valuesSuggest
        data.orderId = this.riskId
        riskFknote(data).then((res) => {
          if (res != null) {
            this.$message.success('风控输出完成')
          } else {
            this.$message('备注失败')
          }
        })
      } else {
        const data = {}
        // data.value=this.valuesSuggest;
        data.orderId = this.riskId
        // console.log(data);
        this.$confirm('是否关闭订单?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(() => {
          orderClose(data).then((res) => {
            riskFknote({ orderId: this.riskId, value: this.valuesSuggest }).then(res => {
              this.$emit('getList')
            })

            // if (res!=null){
            //   this.$message.success('关闭成功');
            //   this.getList();
            // }else {
            //   this.$message('关闭失败');
            // }
          })
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.border-btn {
  height: 25px;
  padding-top: 0;
  padding-bottom: 0;
  background: #ffffff;
  border: 1px solid $mainBlue;
  border-radius: 3px;
  color: $mainBlue;
  font-size: 12px;
}
</style>
